
<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/9
  Time: 23:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>库存管理</title>
</head>
<body>
        <div class="container">
            <br>
            <span style="color:dodgerblue"><strong>您正在做的业务是：库存管理/出入库调度管理/制定入库单</strong></span>
            <br>
            <input type="button" onclick="okdispth()" class="btn btn-default" value="确定">
            <input type="button" class="btn btn-default" value="返回" onclick="outdispathchagtherdang()">
            <div style="width:1000px;height:600px;border:2px black solid">
                <div class="row">
                    <div class="col-md-offset-5"><h2><strong>入库调度单</strong></h2></div>
                </div>
                <br><br><br>
                <div class="row">
                    <div class="col-md-5 col-md-offset-1">
                        <table>
                            <tr>
                                <td>入库单编号:</td>
                                <td><input type="text" name="" id="gatherIddang" style="outline: none;border:none;"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>入库理由:</td>
                                <td><input type="text" name="" id="reasondang" style="outline: none;border:none;"></td>
                            </tr>
                            <tr>
                                <td>入库人:</td>
                                <td><input type="text" name="" id="storerdang" style="outline: none;border:none;"></td>
                            </tr>
                        </table>
                    </div>
                </div>

                <br>
                <br>
                <div style="height:40%">
                    <div class="col-md-offset-10"><button class="btn btn-default" onclick="jiazaigather()"><span class="glyphicon glyphicon-refresh"></span></button></div>
                    <table id="dispathchgaherdangtab">
                    </table>
                </div>



                <br><br>
                <div class="row">
                    <div class="col-md-offset-1 col-md-5">
                        <table>
                            <tr>
                                <td>应入库总件数:</td>
                                <td><input type="text" name="" id="amountSumdang" readonly style="outline: none;border: none"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>应入库总成本:</td>
                                <td><input type="text" name="" id="costPriceSumdang" readonly style="outline: none;border: none"></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <!--调度产品 根据产品id查询-->
        <div class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="dispathchgathermodals">
            <div class="modal-dialog modal-lg">
                <div class="modal-content" id="dangmodalload">

                </div>
            </div>
        </div>
        <script>
            function outdispathchagtherdang() {
                $("#tab1").addTabs("制定入库单", "", "dispatchgather.jsp", true);
                $("#tab1").closeTabs("入库调度单")
                $("#dispatchgathertab").bootstrapTable("refresh")
            }
            $(function () {
                $("#dispathchgaherdangtab").bootstrapTable({
                    contentType: "application/x-www-form-urlencoded", //如果用tomcat就要写这个
                    striped: true,//是否显示隔行变色
                    cache: false,//是否缓存
                    pagination: false,//是否显示分页
                    sortable: false,//是否显示排序
                    clickToSelect: true,//是否启用点击选中行
                    uniqueId:"id",//每一行的唯一标识，一般为主键列,
                    columns:[
                        {
                            field:"",
                            title:"序号",
                            formatter:function (value,row,index) {
                                return Number(index)+1
                            }
                        },
                        {
                            field:"productName",
                            title:"产品名称",
                        },
                        {
                            field:"productId",
                            title:"产品编号",
                        },
                        {
                            field:"amount",
                            title:"应入库件数",
                        },
                        {
                            field:"",
                            title:"调度",
                            formatter:function (value,row,index) {
                               if(row.gatherTag!="K002-2"){
                                   return "<input type='button' value='调度' onclick='dispachgahterByid("+row.productId+")' class='btn btn-success'>"
                               }else {
                                   return "<input type='button'  value='完成'  class='btn btn-default' disabled=disabled>"
                               }
                            }
                        },
                    ]
                })
                dispthchgatherjiazai();
            })
            var ids;
            //加载数据
            function dispthchgatherjiazai(){
                    //获取入库调度的值
                    var gatherId='${param.gatherId}'

                    //获取方法
                    $.post("queryBydispathchGatherdang.action",{"gatherId":gatherId},function (data) {
                        ids=data.id;
                        //赋值
                        $("#gatherIddang").val(data.gatherId)
                        var onsg="";
                        if(data.reason=="R001-1"){
                            onsg="生产入库";
                        }
                        if(data.reason=="R001-2"){
                            onsg="库存初始";
                        }
                        if(data.reason=="R001-3"){
                            onsg="赠送";
                        }
                        if(data.reason=="R001-4"){
                            onsg="内部归还";
                        }
                        if(data.reason=="R001-5"){
                            onsg="其他归还";
                        }
                        $("#reasondang").val(onsg)
                        $("#storerdang").val(data.storer)
                        $("#amountSumdang").val(data.amountSum)
                        $("#costPriceSumdang").val(data.costPriceSum)
                        //获取明细表的值
                        var datas=data.gatherDetails;
                        //定义集合
                        var arr=[];
                        for(var i=0;i<datas.length;i++){
                            //添加
                            arr.push(datas[i])

                        }
                        //追加到表格中
                        $("#dispathchgaherdangtab").bootstrapTable("load",arr)
                    },"json")
            }

            //调度产品 根据产品id查询
            function dispachgahterByid(productId) {
               /* //查询当前产品做了安全库存没
                $.post("queryCellBycheckBytg.action",{"productId":productId},function (data) {
                    console.log(data)
                },"json")*/
                $("#dangmodalload").load("dispathchgathermodals.jsp",{"productId":productId,"ids":ids})
                $("#dispathchgathermodals").modal("show")
            }

            //修改入库表的状态
            function okdispth() {
                if($("input[disabled='disabled']").length<0){
                    alert("请调度产品后在确定")
                    return
                }
                var gatherId=$("#gatherIddang").val();
                $.post("updateGatherBygatherId.action",{"gatherId":gatherId},function (data) {
                    alert(data.msg)
                    $("#tab1").addTabs("制定调度单", "", "dispatchgather.jsp", true);
                    $("#tab1").closeTabs("入库调度单")
                    $("#dispatchgathertab").bootstrapTable("refresh")
                },"json")

            }
            //加载
            function jiazaigather() {
                dispthchgatherjiazai();
            }
        </script>
</body>
</html>
